﻿using System.Security.Cryptography;
using System.Text;

namespace NotWindowsStore.Helpers
{
    public class Md5Helpers
    {
        public static string ComputeHashAsHexString(string str)
        {
            var hash = ComputeHash(str);
            StringBuilder result = new StringBuilder();
            foreach (var b in hash)
            {
                result.Append(b.ToString("x2").ToLower());
            }
            return result.ToString();
        }

        private static byte[] ComputeHash(string str)
        {
            var provider = new MD5CryptoServiceProvider();
            var bytes = Encoding.UTF8.GetBytes(str);
            return provider.ComputeHash(bytes);
        }
    }
}